package com.ctshk.sapp.system.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.system.dto.MainDataAirAirportDTO;
import com.ctshk.rpc.system.req.MainDataAirAirportAddReq;
import com.ctshk.rpc.system.req.MainDataAirAirportListReq;
import com.ctshk.rpc.system.req.MainDataAirAirportUpdateReq;
import com.ctshk.rpc.system.service.IMainDataAirAirportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * <p>
 * 城市-机场 主数据前端控制器
 * </p>
 *
 * @author lihang
 * @since 2021-03-18
 */
@Api(value = "主数据-机场", description = "机场主数据")
@RestController
@RequestMapping("/main-data-air-airport")
public class MainDataAirAirportController extends BaseController {


    @DubboReference
    private IMainDataAirAirportService iMainDataAirAirportService;

    @ApiOperation(value = "新增机场", notes = "新增机场")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "新增机场", operDesc = "新增机场")
    @PostMapping(value = "/add")
    public Result add(@RequestBody @Valid MainDataAirAirportAddReq req) {
        return iMainDataAirAirportService.add(req, getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "查询机场列表", notes = "查询机场列表")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "查询机场列表", operDesc = "查询机场列表")
    @PostMapping(value = "/list")
    public Result<PageResponse<MainDataAirAirportDTO>> list(@RequestBody MainDataAirAirportListReq req) {
        return iMainDataAirAirportService.list(req);
    }

    @ApiOperation(value = "修改机场状态", notes = "修改机场状态")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "修改机场状态", operDesc = "修改机场状态")
    @GetMapping(value = "/update-status/{id}")
    public Result updateStatus(@PathVariable Long id) {
        return iMainDataAirAirportService.updateStatus(id, getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "修改机场信息", notes = "修改机场信息")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "修改机场信息", operDesc = "修改机场信息")
    @PostMapping(value = "/update")
    public Result update(@RequestBody @Valid MainDataAirAirportUpdateReq req) {
        return iMainDataAirAirportService.update(req, getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "机场详情", notes = "机场详情")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "机场详情", operDesc = "修改机场信息")
    @PostMapping(value = "/info/{id}")
    public Result<MainDataAirAirportDTO> update(@PathVariable @NotNull Long id) {
        return iMainDataAirAirportService.info(id);
    }


    @ApiOperation(value = "导入机场主数据", notes = "导入机场主数据")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "导入机场主数据", operDesc = "修改机场信息")
    @PostMapping(value = "/importData")
    public Result importData() {
        return iMainDataAirAirportService.importData();
    }
}
